package com.example.mydemo103;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.mydemo103.DB.UserService;

public class RegietActivity extends AppCompatActivity {
    private Button regist;
    private EditText name,pwd,questpwd,phone;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regiest);
        regist=findViewById(R.id.regist_button);
        name=findViewById(R.id.regist_PersonName);
        pwd=findViewById(R.id.regist_Password);
        questpwd=findViewById(R.id.regist_questpwd);
        phone=findViewById(R.id.regist_Phone);
//        去除广告栏
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }
//        drawable左边图片
        Drawable drawablebyuser=getResources().getDrawable(R.drawable.user);
        drawablebyuser.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        name.setCompoundDrawables(drawablebyuser,null,null,null);
        Drawable drawablebypwd=getResources().getDrawable(R.drawable.pwd);
        drawablebypwd.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        pwd.setCompoundDrawables(drawablebypwd,null,null,null);
        Drawable drawableByPwdQuest=getResources().getDrawable(R.drawable.pwd);
        drawableByPwdQuest.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        questpwd.setCompoundDrawables(drawableByPwdQuest,null,null,null);
        Drawable drawableByPhone=getResources().getDrawable(R.drawable.phone);
        drawableByPhone.setBounds(0,0,45,55);//第一0是距左边距离，第二0是距上边距离，30、35分别是长宽
        phone.setCompoundDrawables(drawableByPhone,null,null,null);



        final UserService userService=new UserService(RegietActivity.this);
        regist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String username =name.getText().toString();
                String password =pwd.getText().toString();
                String quad=questpwd.getText().toString();
                String pphone =phone.getText().toString();
                if(username.equals("")||pphone.equals("")){
                    Toast.makeText(getApplicationContext(),"必须全部填写",Toast.LENGTH_LONG).show();

                }else {
                    if(password.equals(quad)){
                        userService.insertUser(username,password,pphone);
                        Intent intent=new Intent(RegietActivity.this,LgoinActivity.class);
                        startActivity(intent);
                    }else {
                        Toast.makeText(getApplicationContext(),"两次密码要一致",Toast.LENGTH_LONG).show();

                   }
                }
            }
        });
    }
    @Override
    protected void onPause() {
        super.onPause();
        finish();
    }
}